//
//  LoginViewController.m
//  FangXinLang
//
//  Created by apple on 16/9/13.
//  Copyright © 2016年 AJY. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginTableViewCell.h"
#import "UIBarButtonItem+BarButtonItem.h"

@interface LoginViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView * tableView;

@property (nonatomic,strong) UILabel * titleText;
//定义标题label

@property (nonatomic,strong) NSMutableArray * arrMP;//存放六个图标的数组(微信~开心网)

@property (nonatomic,strong) NSMutableArray * arrML;//存放六个名字的数组(微信~开心网)

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addItem];
    self.tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [self.view addSubview:self.tableView];
}
-(void)addItem{
    //添加标题
    self.navigationItem.title = @"登录";
    //添加左边按钮
    UIButton * btnL = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnL setTitle:@"关闭" forState:UIControlStateNormal];
    [btnL setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    UIBarButtonItem * itemL = [UIBarButtonItem barButtonItemWith:btnL andTarget:self andAction:@selector(leftBtn) andImage:nil andImageHeight:nil];
    self.navigationItem.leftBarButtonItem = itemL;
}
#pragma mark 返回按钮事件
-(void)leftBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * temp = nil;
    if (indexPath.section == 0) {
        static NSString * ID = @"login";
        LoginTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [LoginTableViewCell loadLoginTableViewCell];
        }
        temp = cell;
    }else{
        static NSString * ID = @"login";
        LoginTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [LoginTableViewCell loadLoginTableViewCell];
        }
        [self addPL];
       cell.imgView.image = self.arrMP[indexPath.row];
        cell.Name.text = self.arrML[indexPath.row];
        //设置tabelViewCell选中时的颜色(无色)
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        temp = cell;
    }
    return temp;
}
#pragma mark 定义行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55;
}
#pragma mark tableview下面的组里面cell的图标和标题
-(void)addPL{
    self.arrMP = [NSMutableArray array];
    self.arrML = [NSMutableArray array];
    for (int i=1; i<=6; i++){
        NSString * str = [NSString stringWithFormat:@"login_%d@3x",i];
        UIImage * img = [UIImage imageNamed:str];
        [self.arrMP addObject:img];
        if (i==1) {
            NSString * str = @"微信";
            [self.arrML addObject:str];
        }else if (i == 2){
            NSString * str = @"新浪微博";
            [self.arrML addObject:str];
        }else if (i == 3){
            NSString * str = @"腾讯QQ";
            [self.arrML addObject:str];
        }else if (i == 4){
            NSString * str = @"腾讯微博";
            [self.arrML addObject:str];
        }else if (i == 5){
            NSString * str = @"人人网";
            [self.arrML addObject:str];
        }else {
            NSString * str = @"开心网";
            [self.arrML addObject:str];
        }
    }
}
@end
